package com.twu.biblioteca.command;

import com.twu.biblioteca.exception.InvalidSelectionException;

public enum Option {
    SHOW_BOOK(1, "to show all books.", new ShowBookCommand()),
    RESERVE_BOOK(2, "to reserve book.", new ReserveCommand()),
    SHOW_MEMBER_DETAIL(3, "to show membership detail.", new ShowMemberDetailCommand()),
    SHOW_MOVIE(4, "to show all movies.", new ShowMovieCommand()),
    QUIT(5, "to quit.", new QuitComand());

    private Integer code;
    private String description;
    private Command command;

    private Option(Integer code, String description, Command command) {
        this.code = code;
        this.description = description;
        this.command = command;
    }

    public static Option getOptionByInput(String input) throws InvalidSelectionException {
        Integer inputOption = 0;
        try {
            inputOption = Integer.valueOf(input.trim());
        } catch (NumberFormatException e) {
            throw new InvalidSelectionException(InvalidSelectionException.INVALID_OPTION);
        }
        switch (inputOption) {
            case 1:
                return SHOW_BOOK;
            case 2:
                return RESERVE_BOOK;
            case 3:
                return SHOW_MEMBER_DETAIL;
            case 4:
                return SHOW_MOVIE;
            case 5:
                return QUIT;
            default:
                throw new InvalidSelectionException(InvalidSelectionException.INVALID_OPTION);
        }
    }

    public String getDescription() {
        return description;
    }

    public Command getCommand() {
        return command;
    }

    public Integer getCode() {
        return code;
    }
}
